﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;

namespace TShock_IslandWar
{
    public class Config
    {
        public List<List<int>> ItemWallGenerator = new List<List<int>>();
        public ushort RedSpawnTile = TileID.TeamBlockRed;
        public ushort BlueSpawnTile = TileID.TeamBlockBlue;
        public ushort BedTile = TileID.Beds;
        public ICollection<ushort> AllowDestroy = new HashSet<ushort>();

        public int[] LeftTop = new int[2] { 0,0};
        public int[] RightBottom = new int[2] {8000,4000 };

        public static string path = "./tshock/islandwar.json";
        private Config()
        {

        }
        public static Config LoadConfig()
        {
            Config config;
            if (!File.Exists(path))
            {
                config = new Config();
                config.ItemWallGenerator.Add(new List<int>{ WallID.Wood, ItemID.Wood, 1, 40 });
                config.ItemWallGenerator.Add(new List<int>{ WallID.Stone, ItemID.StoneBlock, 1, 2000 });
                config.ItemWallGenerator.Add(new List<int>{ WallID.IronBrick, ItemID.IronOre, 1, 400 });
                config.ItemWallGenerator.Add(new List<int> { WallID.GoldBrick, ItemID.GoldOre, 1, 450 });
                config.ItemWallGenerator.Add(new List<int>{ WallID.SilverBrick, ItemID.SilverOre, 1, 400 });
                config.ItemWallGenerator.Add(new List<int>{ WallID.DiamondEcho, ItemID.Geode, 1, 1800 });
                config.ItemWallGenerator.Add(new List<int> { WallID.CopperBrick, ItemID.CopperCoin, 1, 100 });

                config.AllowDestroy.Add(TileID.WoodBlock);
                config.AllowDestroy.Add(TileID.ShadowOrbs);

                File.WriteAllText(path, JsonConvert.SerializeObject(config));
                return config;
            }
            config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(path));
            return config;
        }
    }
}
